﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using CTEM.Models;
using System.Collections.Generic;

namespace CTEM.ModuleForms.ManageReport
{
    public partial class XtraLedgerReport : DevExpress.XtraReports.UI.XtraReport
    {
        public XtraLedgerReport()
        {
            InitializeComponent();
        }
        public void DataBind(List<LedgerDTO> listLedger, DateTime fromTime, DateTime toTime)
        {
            long totalMoney = 0;
            lbToDay.Text = fromTime.ToString("dd/MM/yyyy");
            lbFromday.Text = toTime.ToString("dd/MM/yyyy");
            if (listLedger.Count > 0)
            {
                lName.Text = "BÁO CÁO PHIẾU "+ listLedger[0].Type.ToUpper();
                if (listLedger[0].Type.Equals("Chi"))
                    lPeople.Text = listLedger[0].Type + " Cho";
                else
                    lPeople.Text = listLedger[0].Type + " từ";
            }

            foreach (var ledger in listLedger)
            {
                totalMoney += ledger.Number;
                XRTableRow rowtitle = new XRTableRow();
                rowtitle.Name = "row 1";
                rowtitle.WidthF = 830;
                rowtitle.HeightF = 30;
                // LedgerCode
                XRTableCell clLedgerCode = new XRTableCell();

                clLedgerCode.Name = "clName";
                clLedgerCode.Text = Convert.ToString(ledger.Name);
                clLedgerCode.WidthF = 90;
                clLedgerCode.HeightF = 30;
                rowtitle.Cells.Add(clLedgerCode);

                // monney
                XRTableCell clNumber = new XRTableCell();
                clNumber.Name = "clSalary";
                clNumber.Text =ledger.Number.ToString("n0");
                clNumber.WidthF = 95;
                clNumber.HeightF = 30;
                rowtitle.Cells.Add(clNumber);

                // Person
                XRTableCell clPerson = new XRTableCell();
                clPerson.Name = "clTotalAllowance";
                clPerson.Text = Convert.ToString(ledger.Person);
                clPerson.WidthF = 150;
                clPerson.HeightF = 30;
                rowtitle.Cells.Add(clPerson);

                // Method
                XRTableCell clSMethod = new XRTableCell();
                clSMethod.Name = "clSalary";
                clSMethod.Text = Convert.ToString(ledger.Method);
                clSMethod.WidthF = 100;
                clSMethod.HeightF = 30;
                rowtitle.Cells.Add(clSMethod);


                // Date
                XRTableCell clSDate = new XRTableCell();
                clSDate.Name = "clDate";
                clSDate.Text = ledger.Date.ToString("dd/MM/yyyy");
                rowtitle.Cells.Add(clSDate);

                // reason
                XRTableCell clSReason = new XRTableCell();
                clSReason.Name = "clReason";
                clSReason.Text = ledger.Reason;
                clSReason.WidthF = 305;
                clSReason.HeightF = 30;
                rowtitle.Cells.Add(clSReason);
                xrTable1.Rows.Add(rowtitle);


            }
            lTotalDebt.Text = totalMoney.ToString("n0");

        }
    }
}
